* …
=== New developer features in 1.34 ===
-* …
+* Language::formatTimePeriod now supports the new 'avoidhours' option to output
+ strings like "5 days ago" instead of "5 days 13 hours ago".
=== External library changes in 1.34 ===
==== New external libraries ====
*
* @param int|float $seconds
* @param array $format An optional argument that formats the returned string in different ways:
+ * If $format['avoid'] === 'avoidhours': don't show hours, just show days
* If $format['avoid'] === 'avoidseconds': don't show seconds if $seconds >= 1 hour,
* If $format['avoid'] === 'avoidminutes': don't show seconds/minutes if $seconds > 48 hours,
* If $format['noabbrevs'] is true: use 'seconds' and friends instead of 'seconds-abbrev'
$s = $hoursMsg->params( $this->formatNum( $hours ) )->text();
$s .= ' ';
$s .= $minutesMsg->params( $this->formatNum( $minutes ) )->text();
- if ( !in_array( $format['avoid'], [ 'avoidseconds', 'avoidminutes' ] ) ) {
+ if ( !in_array( $format['avoid'], [ 'avoidseconds', 'avoidminutes', 'avoidhours' ] ) ) {
$s .= ' ' . $secondsMsg->params( $this->formatNum( $secondsPart ) )->text();
}
} else {
$days = floor( $seconds / 86400 );
- if ( $format['avoid'] === 'avoidminutes' ) {
+ if ( $format['avoid'] === 'avoidhours' ) {
+ $hours = round( ( $seconds - $days * 86400 ) / 3600 );
+ if ( $hours == 24 ) {
+ $hours = 0;
+ $days++;
+ }
+ $s = $daysMsg->params( $this->formatNum( $days ) )->text();
+ } elseif ( $format['avoid'] === 'avoidminutes' ) {
$hours = round( ( $seconds - $days * 86400 ) / 3600 );
if ( $hours == 24 ) {
$hours = 0;
'48 hours 0 minutes',
'formatTimePeriod() rounding (=48h), avoidseconds'
],
+ [
+ 259199.55,
+ 'avoidhours',
+ '3 d',
+ 'formatTimePeriod() rounding (>48h), avoidhours'
+ ],
+ [
+ 259199.55,
+ [ 'avoid' => 'avoidhours', 'noabbrevs' => true ],
+ '3 days',
+ 'formatTimePeriod() rounding (>48h), avoidhours'
+ ],
[
259199.55,
'avoidminutes',